package core.service.net;

import java.io.IOException;

import org.springframework.stereotype.Component;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

@Component
public class HttpUtils {

	public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
	
	public static String request(String url, String json) throws IOException {
		
		OkHttpClient client = new OkHttpClient();
		RequestBody body = RequestBody.create(JSON, json);
		Request req = new Request.Builder()
				.url(url)
				.get()
				.build();
		
		Response resp = client.newCall(req).execute();
		return resp.body().string();
	}
}